import java.util.Arrays;
import java.util.PriorityQueue;

/**
 * @Author ZhangCuirong
 * @Date 2025/9/8 14:24
 * @description:
 */
public class LCR159 {
    public int[] inventoryManagement(int[] stock, int cnt) {
        int[] res = new int[cnt];
        PriorityQueue<Integer> heap = new PriorityQueue<>((x1, x2) -> x2 - x1);
        for (int i = 0; i < stock.length; i++) {
            if (cnt != 0) {
                heap.add(stock[i]);
                cnt--;
            } else {
                heap.offer(stock[i]);
                heap.poll();
            }
        }
        for (int i = 0; i < res.length; i++) {
            res[i] = heap.poll();
        }
        return res;
    }

    public static void main(String[] args) {
        LCR159 s = new LCR159();
        System.out.println(Arrays.toString(s.inventoryManagement(new int[]{2, 5, 7, 4}, 1)));
    }
}
